home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxobj.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.8 KB  |  171 lines

  1. /* Copyright (C) 1995, 1996, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxobj.h,v 1.2 2000/09/19 19:00:39 lpd Exp $ */
  20. /* Memory manager implementation structures for Ghostscript */
  21.  
  22. #ifndef gxobj_INCLUDED
  23. #  define gxobj_INCLUDED
  24.  
  25. #include "gxbitmap.h"
  26.  
  27. /* ================ Objects ================ */
  28.  
  29. /*
  30.  * Object headers have the form:
  31.     -l- -mark/back-
  32.     -size-
  33.     -type/reloc-
  34.  * l (aLone) is a single bit.  Mark/back is 1 bit shorter than a uint.  We
  35.  * round the header size up to the next multiple of the most severe
  36.  * alignment restriction (4 or 8 bytes).
  37.  *
  38.  * The mark/back field is used for the mark during the marking phase of
  39.  * garbage collection, and for a back pointer value during the compaction
  40.  * phase.  Since we want to be able to collect local VM independently of
  41.  * global VM, we need two different distinguished mark values:
  42.  *      - For local objects that have not been traced and should be freed
  43.  *      (compacted out), we use 1...11 in the mark field (o_unmarked).
  44.  *      - For global objects that have not been traced but should be kept,
  45.  *      we use 1...10 in the mark field (o_untraced).
  46.  * Note that neither of these values is a possible real relocation value.
  47.  *
  48.  * The back pointer's meaning depends on whether the object is
  49.  * free (unmarked) or in use (marked):
  50.  *      - In free objects, the back pointer is an offset from the object
  51.  * header back to a chunk_head_t structure that contains the location
  52.  * to which all the data in this chunk will get moved; the reloc field
  53.  * contains the amount by which the following run of useful objects
  54.  * will be relocated downwards.
  55.  *      - In useful objects, the back pointer is an offset from the object
  56.  * back to the previous free object; the reloc field is not used (it
  57.  * overlays the type field).
  58.  * These two cases can be distinguished when scanning a chunk linearly,
  59.  * but when simply examining an object via a pointer, the chunk pointer
  60.  * is also needed.
  61.  */
  62. #define obj_flag_bits 1
  63. #define obj_mb_bits (arch_sizeof_int * 8 - obj_flag_bits)
  64. #define o_unmarked (((uint)1 << obj_mb_bits) - 1)
  65. #define o_set_unmarked(pp)\
  66.   ((pp)->o_smark = o_unmarked)
  67. #define o_is_unmarked(pp)\
  68.   ((pp)->o_smark == o_unmarked)
  69. #define o_untraced (((uint)1 << obj_mb_bits) - 2)
  70. #define o_set_untraced(pp)\
  71.   ((pp)->o_smark = o_untraced)
  72. #define o_is_untraced(pp)\
  73.   ((pp)->o_smark == o_untraced)
  74. #define o_marked 0
  75. #define o_mark(pp)\
  76.   ((pp)->o_smark = o_marked)
  77. #define obj_back_shift obj_flag_bits
  78. #define obj_back_scale (1 << obj_back_shift)
  79. typedef struct obj_header_data_s {
  80.     union _f {
  81.     struct _h {
  82.         unsigned alone:1;
  83.     } h;
  84.     struct _m {
  85.         unsigned _:1, smark:obj_mb_bits;
  86.     } m;
  87.     struct _b {
  88.         unsigned _:1, back:obj_mb_bits;
  89.     } b;
  90.     } f;
  91.     uint size;
  92.     union _t {
  93.     gs_memory_type_ptr_t type;
  94.     uint reloc;
  95.     } t;
  96. } obj_header_data_t;
  97.  
  98. /*
  99.  * Define the alignment modulus for aligned objects.  We assume all
  100.  * alignment values are powers of 2; we can avoid nested 'max'es that way.
  101.  * The final | is because back pointer values are divided by obj_back_scale,
  102.  * so objects must be aligned at least 0 mod obj_back_scale.
  103.  */
  104. #define obj_align_mod\
  105.   (((arch_align_long_mod - 1) | (arch_align_ptr_mod - 1) |\
  106.     (arch_align_double_mod - 1) | (align_bitmap_mod - 1) |\
  107.     (obj_back_scale - 1)) + 1)
  108. /* The only possible values for obj_align_mod are 4, 8, or 16.... */
  109. #if obj_align_mod == 4
  110. #  define log2_obj_align_mod 2
  111. #else
  112. #if obj_align_mod == 8
  113. #  define log2_obj_align_mod 3
  114. #else
  115. #if obj_align_mod == 16
  116. #  define log2_obj_align_mod 4
  117. #endif
  118. #endif
  119. #endif
  120. #define obj_align_mask (obj_align_mod-1)
  121. #define obj_align_round(siz)\
  122.   (uint)(((siz) + obj_align_mask) & -obj_align_mod)
  123. #define obj_size_round(siz)\
  124.   obj_align_round((siz) + sizeof(obj_header_t))
  125.  
  126. /* Define the real object header type, taking alignment into account. */
  127. struct obj_header_s {        /* must be a struct because of forward reference */
  128.     union _d {
  129.     obj_header_data_t o;
  130.     byte _pad[ROUND_UP(sizeof(obj_header_data_t), obj_align_mod)];
  131.     }
  132.     d;
  133. };
  134.  
  135. /* Define some reasonable abbreviations for the fields. */
  136. #define o_alone d.o.f.h.alone
  137. #define o_back d.o.f.b.back
  138. #define o_smark d.o.f.m.smark
  139. #define o_size d.o.size
  140. #define o_type d.o.t.type
  141. #define o_nreloc d.o.t.reloc
  142.  
  143. /*
  144.  * The macros for getting the sizes of objects all take pointers to
  145.  * the object header, for use when scanning storage linearly.
  146.  */
  147. #define pre_obj_contents_size(pp)\
  148.   ((pp)->o_size)
  149.  
  150. #define pre_obj_rounded_size(pp)\
  151.   obj_size_round(pre_obj_contents_size(pp))
  152. #define pre_obj_next(pp)\
  153.   ((obj_header_t *)((byte *)(pp) + obj_align_round(\
  154.     pre_obj_contents_size(pp) + sizeof(obj_header_t) )))
  155.  
  156. /*
  157.  * Define the header that free objects point back to when relocating.
  158.  * Every chunk, including inner chunks, has one of these.
  159.  */
  160. typedef struct chunk_head_s {
  161.     byte *dest;            /* destination for objects */
  162. #if obj_align_mod > arch_sizeof_ptr
  163.     byte *_pad[obj_align_mod / arch_sizeof_ptr - 1];
  164. #endif
  165.     obj_header_t free;        /* header for a free object, */
  166.     /* in case the first real object */
  167.     /* is in use */
  168. } chunk_head_t;
  169.  
  170. #endif /* gxobj_INCLUDED */
  171.